<?php

namespace app\admin\controller;
//  1引入基类控制器
use app\common\controller\Base;

use think\facade\Request;

// 2. 把原来继承控制器的改成Base
// extends Controller -> extends Base
class Admin extends Base
{
    // 3.里面定义方法，这里用于获取用户列表并返回给前台
    public function getUsers()
    {
        // 调用模型查询数据库数据
        $data = \app\admin\model\Admin::select();
        // 将数据返回给前台
        $this->ok($data);
    }
    //添加用户
    public function add()
    {
        //接受数据
        $param = Request::param();


        $data = [

            'username' => $param['name'],
            'password' => $param['password'],
            'email' => $param['email'],
            'nickname' => $param['nickname']
        ];
        $res = \app\home\model\Admin::create($data);
        $this->ok($res);
    }
    //修改用户
    public function xgadd()
    {
        $param = Request::param();

        $res = \app\home\model\Admin::where('id', $param['id'])->update([
            'username' => $param['username'],
            'password' => $param['password'],
            'email' => $param['email'],
            'nickname' => $param['nickname']
        ]);
        $this->ok($res);
    }
    //删除用户
    public function adminsc()
    {
        $param = Request::param();

        $res = \app\home\model\Admin::where('id', $param['id'])->delete();
        $this->ok($res);
    }
    //订单列表
    public function getOrder()
    {
        $data = \app\home\model\Cartshop::alias('o')
            ->field('o.*,g.goods_name,a.username,g.images')
            ->join('spec_goods g', 'o.goods_id=g.id', 'left')
            ->join('admin a', 'o.user_id=a.id', 'left')
            ->select();
        $this->ok($data);
    }
}
